<?
	define('_VIEW_MODEL_','admin');
	session_start();
	$statu = $_SESSION['statu'];
	require_once '../init.php';
	$title ="";
	$level = "";
	if(!$statu){
		echo "<script>window.parent.location.href='./index.php'</script>";
	}
	if(isset($action)&&$action == "add"){
		$name = $helpname;
		$styl = $bbssty;
		$su   = explode(",", $styl);
		$rank = $helprank;
		$sta  = $helpsta;
		$sty  = $su['0'];
		$lev  = $su['1'];
		//echo "insert into {$telper}bbs_column set `title` = '$name',`rank` = '$rank',`level`=$lev,`pid` = '$sty',`state` = '$sta'";exit;
		$db->Execute("insert into {$telper}bbs_column set `title` = '$name',`rank` = '$rank',`level`=$lev,`pid` = '$sty',`state` = '$sta'");
		header("Location:bbscontlist.php");
		exit;
	}
	if(isset($action)&&$action == "edit"){
		$id   = $vid;
		$name = $helpname;
		$sty  = $bbssty;
		$rank = $helprank;
		$sta  = $helpsta;
		$db->Execute("update {$telper}bbs_column set `title` = '$name',`rank` = '$rank',`pid` = '$sty',`state` = '$sta' where id = '$id'");
		header("Location:bbscontlist.php");
		exit;
	}
	if(isset($act)&&$act=="edit"){
		$act = $act;
		$namevalue = $adminbbsedit;
		$id  = intval($id);
		$inf = $db->GetRow("select * from {$telper}bbs_column where id=$id");
		if($inf['pid'] == '0'){
			$title = "顶级版块";
			$tip   = $inf['pid'];
		}else{
			$ti = $db->GetRow("select `title`,`level` from {$telper}bbs_column where id = '$inf[pid]'");
			$title = $ti['title'];
			$level = $ti['level'];
			$tip   = $inf['pid'];
		}
	}else{
		$act = "add";
		$namevalue = $adminbbsadd;
		$inf = "";
		$id  = "";
		$tip = "";
		$rs = $db->Execute("select `id`,`title`,`level` from {$telper}bbs_column where level <3 order by rank asc");
		$info = $rs->GetArray();
		foreach ($info as $k=>$v){
			$title[$k]['id']=$v['id'];
			$title[$k]['ti']=$v['title'];
			$title[$k]['level']=$v['level'];
		}
	}
	echo $level;
	$smartyObj->assign("namevalue",$namevalue);
	$smartyObj->assign("act",$act);
	$smartyObj->assign("inf",$inf);
	$smartyObj->assign("titl",$title);
	$smartyObj->assign('vid',$id);
	$smartyObj->assign('tid',$tip);
	$smartyObj->assign('level',$level);
	$smartyObj->assign("title",$admintitle);
	$smartyObj->display("bbscontadd.tpl");
?>